<?php

class Recruiter_RegisterController extends Zend_Controller_Action
{
	public function init()
	{
		
	}
	
	public function indexAction()
	{
//		$model = new RP_Model_DbTable_Industry();
//		$rowSet = $model->fetchAllIndustries();
//		$this->view->assign('industrySet',$rowSet);	
	}
	
	public function registerAction(){
		$this->_helper->viewRenderer->setNoRender(TRUE);
		$this->_helper->layout()->disableLayout();
		
			$request = $this->getRequest();
		
		$param = array(
					'username'=>$request->getParam("username"),
					'password'=>$request->getParam("password"),
					'email'=>$request->getParam("email"),
					'recruiter_name'=>$request->getParam("recruiter_name"),
					'recruiter_type'=>$request->getParam("recruiter_type"),
					'contact_person'=>$request->getParam("contact_person"),
					'contact_no'=>$request->getParam("contact_no"),
					'alternate_no'=>$request->getParam("alternate_no"),
					'addressline'=>$request->getParam("addressline"),
					'city'=>$request->getParam("city"),
					'district'=>$request->getParam("district"),
					'state'=>$request->getParam("state"),
					'pincode'=>$request->getParam("pincode"),	
				 );	 
		
		$logger = Zend_Registry::get("logger");
		$logger->debug($param);
		
		switch($request->getParam("oper")){
			case 'add':
				
				$model = new RP_Model_User_Recruiter($param);
				if(!$model->isUsernameAvailable()){
					echo "Username Not Available";
					return;
				}
				if(!$model->isEmailAvailable()){
					echo "Recruiter accoount with ".$model->getEmail()." already exist.";
					return;
				}
				if($model->register()){	
					echo $model->getRecruiter_name().
                     ' is now registered as job seeker.';
                    return;
				}
				break;
				
			default:
				throw new Zend_Exception('"' . $oper . '" is unknown operation.', 
                Zend_Log::ERR);
                break;
		}
		throw new Zend_Exception(
        'Operation on job seeker "' . $model->getUsername() . '" not successfull.', 
        Zend_Log::ERR);
	
	}
}